package com.carworld.controller;

import org.apache.log4j.Logger;

import com.jfinal.kit.PropKit;
import com.jfinal.weixin.iot.msg.InEquDataMsg;
import com.jfinal.weixin.iot.msg.InEqubindEvent;
import com.jfinal.weixin.sdk.api.ApiConfig;
import com.jfinal.weixin.sdk.jfinal.MsgController;
import com.jfinal.weixin.sdk.msg.in.InImageMsg;
import com.jfinal.weixin.sdk.msg.in.InLinkMsg;
import com.jfinal.weixin.sdk.msg.in.InLocationMsg;
import com.jfinal.weixin.sdk.msg.in.InNotDefinedMsg;
import com.jfinal.weixin.sdk.msg.in.InShortVideoMsg;
import com.jfinal.weixin.sdk.msg.in.InTextMsg;
import com.jfinal.weixin.sdk.msg.in.InVideoMsg;
import com.jfinal.weixin.sdk.msg.in.InVoiceMsg;
import com.jfinal.weixin.sdk.msg.in.card.InCardPassCheckEvent;
import com.jfinal.weixin.sdk.msg.in.card.InCardPayOrderEvent;
import com.jfinal.weixin.sdk.msg.in.card.InCardSkuRemindEvent;
import com.jfinal.weixin.sdk.msg.in.card.InUserCardEvent;
import com.jfinal.weixin.sdk.msg.in.card.InUserConsumeCardEvent;
import com.jfinal.weixin.sdk.msg.in.card.InUserGetCardEvent;
import com.jfinal.weixin.sdk.msg.in.card.InUserGiftingCardEvent;
import com.jfinal.weixin.sdk.msg.in.event.InCustomEvent;
import com.jfinal.weixin.sdk.msg.in.event.InFollowEvent;
import com.jfinal.weixin.sdk.msg.in.event.InLocationEvent;
import com.jfinal.weixin.sdk.msg.in.event.InMassEvent;
import com.jfinal.weixin.sdk.msg.in.event.InMenuEvent;
import com.jfinal.weixin.sdk.msg.in.event.InNotDefinedEvent;
import com.jfinal.weixin.sdk.msg.in.event.InPoiCheckNotifyEvent;
import com.jfinal.weixin.sdk.msg.in.event.InQrCodeEvent;
import com.jfinal.weixin.sdk.msg.in.event.InShakearoundUserShakeEvent;
import com.jfinal.weixin.sdk.msg.in.event.InTemplateMsgEvent;
import com.jfinal.weixin.sdk.msg.in.event.InVerifyFailEvent;
import com.jfinal.weixin.sdk.msg.in.event.InVerifySuccessEvent;
import com.jfinal.weixin.sdk.msg.in.event.InWifiEvent;
import com.jfinal.weixin.sdk.msg.in.speech_recognition.InSpeechRecognitionResults;
import com.jfinal.weixin.sdk.msg.out.OutImageMsg;
import com.jfinal.weixin.sdk.msg.out.OutNewsMsg;
import com.jfinal.weixin.sdk.msg.out.OutTextMsg;
import com.jfinal.weixin.sdk.msg.out.OutVoiceMsg;

public class WeixinMsgController extends MsgController {
	  static Logger logger = Logger.getLogger(WeixinMsgController.class);
	public ApiConfig getApiConfig() {
		ApiConfig ac = new ApiConfig();
		
		// 配置微信 API 相关常量
		ac.setToken(PropKit.get("token"));
		ac.setAppId(PropKit.get("appIdUser"));
		ac.setAppSecret(PropKit.get("appSecretUser"));
		
		/**
		 *  是否对消息进行加密，对应于微信平台的消息加解密方式：
		 *  1：true进行加密且必须配置 encodingAesKey
		 *  2：false采用明文模式，同时也支持混合模式
		 */
		ac.setEncryptMessage(PropKit.getBoolean("encryptMessage", false));
		ac.setEncodingAesKey(PropKit.get("encodingAesKey", "setting it in config file"));
		return ac;
	}

	@Override
	protected void processInShakearoundUserShakeEvent(
			InShakearoundUserShakeEvent inShakearoundUserShakeEvent) {
		// TODO Auto-generated method stub

	}

	@Override
	protected void processInVerifySuccessEvent(
			InVerifySuccessEvent inVerifySuccessEvent) {
		// TODO Auto-generated method stub

	}

	@Override
	protected void processInVerifyFailEvent(InVerifyFailEvent inVerifyFailEvent) {
		// TODO Auto-generated method stub

	}

	@Override
	protected void processInPoiCheckNotifyEvent(
			InPoiCheckNotifyEvent inPoiCheckNotifyEvent) {
		// TODO Auto-generated method stub

	}

	@Override
	protected void processInWifiEvent(InWifiEvent inWifiEvent) {
		// TODO Auto-generated method stub

	}

	@Override
	protected void processIsNotDefinedEvent(InNotDefinedEvent inNotDefinedEvent) {
		// TODO Auto-generated method stub

	}

	@Override
	protected void processIsNotDefinedMsg(InNotDefinedMsg inNotDefinedMsg) {
		// TODO Auto-generated method stub

	}

	@Override
	protected void processInCardPassCheckEvent(InCardPassCheckEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void processInCardPayOrderEvent(InCardPayOrderEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void processInCardSkuRemindEvent(InCardSkuRemindEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void processInEquDataMsg(InEquDataMsg arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void processInEqubindEvent(InEqubindEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void processInMerChantOrderEvent(com.jfinal.weixin.sdk.msg.in.card.InMerChantOrderEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void processInUpdateMemberCardEvent(com.jfinal.weixin.sdk.msg.in.card.InUpdateMemberCardEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void processInUserCardEvent(InUserCardEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	protected void processInUserConsumeCardEvent(InUserConsumeCardEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void processInUserGetCardEvent(InUserGetCardEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void processInUserGiftingCardEvent(InUserGiftingCardEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void processInUserPayFromCardEvent(com.jfinal.weixin.sdk.msg.in.card.InUserPayFromCardEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	
	
	/**
     * 实现父类抽方法，处理文本消息
     * 本例子中根据消息中的不同文本内容分别做出了不同的响应，同时也是为了测试 jfinal weixin sdk的基本功能：
     *     本方法仅测试了 OutTextMsg、OutNewsMsg、OutMusicMsg 三种类型的OutMsg，
     *     其它类型的消息会在随后的方法中进行测试
     */
    protected void processInTextMsg(InTextMsg inTextMsg) {
    	OutTextMsg outMsg = new OutTextMsg(inTextMsg);
        outMsg.setContent("感谢您给予我们宝贵的支持，客服会尽快处理您的留言，谢谢~~");
        render(outMsg);
    }

    /**
     * 实现父类抽方法，处理图片消息
     */
    protected void processInImageMsg(InImageMsg inImageMsg) {
    	// TODO Auto-generated method stub
    }

    /**
     * 实现父类抽方法，处理语音消息
     */
    protected void processInVoiceMsg(InVoiceMsg inVoiceMsg) {
    	// TODO Auto-generated method stub
    }

    /**
     * 实现父类抽方法，处理视频消息
     */
    protected void processInVideoMsg(InVideoMsg inVideoMsg) {
    	// TODO Auto-generated method stub
    }

    @Override
    protected void processInShortVideoMsg(InShortVideoMsg inShortVideoMsg)
    {
    	// TODO Auto-generated method stub
    }

    /**
     * 实现父类抽方法，处理地址位置消息
     */
    protected void processInLocationMsg(InLocationMsg inLocationMsg) {
    	// TODO Auto-generated method stub
    }

    /**
     * 实现父类抽方法，处理链接消息
     * 特别注意：测试时需要发送我的收藏中的曾经收藏过的图文消息，直接发送链接地址会当做文本消息来发送
     */
    protected void processInLinkMsg(InLinkMsg inLinkMsg) {
    	// TODO Auto-generated method stub
    }

    @Override
    protected void processInCustomEvent(InCustomEvent inCustomEvent)
    {
    	// TODO Auto-generated method stub
    }

    /**
     * 实现父类抽方法，处理关注/取消关注消息
     * 如果为取消关注事件，将无法接收到传回的信息
     */
    protected void processInFollowEvent(InFollowEvent inFollowEvent) {
    	 OutNewsMsg outMsg = new OutNewsMsg(inFollowEvent);
         outMsg.addNews(
              "送你一张茉德精品火锅10元优惠券",
              "",
              "http://food.cloudwest.cn/carworld_weixin/images/activity/logo.jpg",
              "http://food.3kkk.xyz/carworld_weixin/vipcard/receivedCoupon?couponMealId=1575996360731&status=coupon");
         outMsg.addNews("茉德火锅欢迎您的到来，冬日吃火锅让生活更美好~", "", "http://food.cloudwest.cn/carworld_weixin/images/activity/logo.jpg", "http://food.3kkk.xyz/carworld_weixin/vipcard/receivedCoupon?couponMealId=1575996360731&status=coupon");
         // 如果为取消关注事件，将无法接收到传回的信息
         render(outMsg);
    }

    /**
     * 实现父类抽方法，处理扫描带参数二维码事件
     */
    protected void processInQrCodeEvent(InQrCodeEvent inQrCodeEvent) {
    	// TODO Auto-generated method stub
    }

    /**
     * 实现父类抽方法，处理上报地理位置事件
     */
    protected void processInLocationEvent(InLocationEvent inLocationEvent) {
    	// TODO Auto-generated method stub
    }

    @Override
    protected void processInMassEvent(InMassEvent inMassEvent)
    {
        System.out.println("processInMassEvent() 方法测试成功");
    }

    /**
     * 实现父类抽方法，处理自定义菜单事件
     */
    protected void processInMenuEvent(InMenuEvent inMenuEvent) {
    	// TODO Auto-generated method stub
    }

    /**
     * 实现父类抽方法，处理接收语音识别结果
     */
    protected void processInSpeechRecognitionResults(InSpeechRecognitionResults inSpeechRecognitionResults) {
    	// TODO Auto-generated method stub
    }

    // 处理接收到的模板消息是否送达成功通知事件
    protected void processInTemplateMsgEvent(InTemplateMsgEvent inTemplateMsgEvent) {
    	// TODO Auto-generated method stub
    }

	
}
